package com.echoesnet.echoesshortvideo.Persistence;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;

import java.util.List;

import static android.arch.persistence.room.OnConflictStrategy.REPLACE;

/**
 * Copyright (C) 2018 科技发展有限公司
 * 完全享有此软件的著作权，违者必究
 *
 * @author ben
 * @version 1.0
 * @modifier
 * @createDate 2018/4/19 20:37
 * @description
 */
@Dao
public interface TinyVideoInfoDao
{
    @Insert(onConflict = REPLACE)
    void save(TinyVideoInfoEntity infoEntity);

    @Insert(onConflict = REPLACE)
    void insertAll(TinyVideoInfoEntity... infoEntities);

    @Delete
    void delete(TinyVideoInfoEntity infoEntity);

    @Query("DELETE FROM TinyVideoInfo")
    void deleteAll();

    @Query("SELECT * FROM TinyVideoInfo WHERE videoId = :videoId")
    LiveData<TinyVideoInfoEntity> load(String videoId);

    @Query("SELECT * FROM TinyVideoInfo WHERE videoId IN (:videoIds)")
    LiveData<List<TinyVideoInfoEntity>> loadAllByIds(String[] videoIds);

    @Query("SELECT * FROM TinyVideoInfo")
    LiveData<List<TinyVideoInfoEntity>> loadAll();

    @Query("SELECT * FROM TinyVideoInfo ORDER BY date DESC")
    LiveData<List<TinyVideoInfoEntity>> loadAllByUpdate();

    @Query("DELETE FROM TinyVideoInfo where videoId NOT IN (:videoIds)")
    void deleteByIds(String[] videoIds);

}
